#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int NN = 1e5 + 4;
struct Edge {
  int v, w;
};
LL Dis[NN];
int N, L, M, UP[NN][18], Tin[NN], Tout[NN], Timer;
vector<Edge> G[NN];
void dfs(int u, int fa) {
  UP[u][0] = fa, Tin[u] = ++Timer;
  for (int i = 1; i <= L; ++i) UP[u][i] = UP[UP[u][i - 1]][i - 1];
  for (const Edge &e : G[u])
    if (e.v != fa) Dis[e.v] = Dis[u] + e.w, dfs(e.v, u);
  Tout[u] = ++Timer;
}
bool isAncestor(int u, int v) { return Tin[u] <= Tin[v] && Tout[u] >= Tout[v]; }
int lca(int u, int v) {
  if (isAncestor(v, u)) return v;
  if (isAncestor(u, v)) return u;
  for (int i = L; i >= 0; --i)
    if (!isAncestor(UP[u][i], v)) u = UP[u][i];
  return UP[u][0];
}
LL dist(int u, int v) { return (LL)Dis[u] + Dis[v] - Dis[lca(u, v)] * 2ll; }
struct NodeComp {
  bool operator()(int u, int v) const { return Tin[u] < Tin[v]; }
};
set<int, NodeComp> S;
typedef set<int, NodeComp>::iterator SIT;
inline SIT leftOf(SIT it) {
  if (it == S.begin()) return --S.end();
  return --it;
}
inline SIT rightOf(SIT it) {
  if (++it == S.end()) return S.begin();
  return it;
}
inline LL diff(int u) {
  SIT i = S.find(u), r = rightOf(i), l = leftOf(i);
  return dist(u, *l) + dist(u, *r) - dist(*l, *r);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> N >> M, Timer = 0, L = ceil(log2(N));
  for (int i = 1, u, v, w; i <= N - 1; ++i)
    cin >> u >> v >> w, G[u].push_back({v, w}), G[v].push_back({u, w});
  dfs(1, 1);
  LL ans = 0;
  for (int i = 1, u; i <= M; ++i) {
    cin >> u;
    if (S.count(u))
      ans -= diff(u), S.erase(u);
    else
      S.insert(u), ans += diff(u);
    cout << ans << endl;
  }
  return 0;
}
